//
//Copyright GX. Yuan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @file net.go
 * @brief Leetcode 剑指Offer 第二版
 * @details 剑指 Offer 14- I. 剪绳子
 * @author GX. Yuan  any question please send mail to yuanguanxu@qq.com
 * @date 2021-6-28
 * @version V1.0
 * @attention 硬件平台: windows 10 家庭版
 * SDK版本：Go 1.16.5
 * IDE版本：GoLand 2020.2.3
 */
package main

func cuttingRope(n int) int {
	if n == 2 {
		return 1
	}
	if n == 3 {
		return 2
	}
	result:=1
	// 当大于4的时候，按照3 进行拆分，当小于等于4 不用进行拆分，因为小于4 进行拆分，只会月拆越小
	for n>4{
		n-=3
		result = result *3 % 1000000007
	}
	return n * result %1000000007
}

// 实现的思路
// 两层循环
// 根据数学公式进行推导出:
// 把绳子切成等长为3时，得到的乘积最大！
// 这里使用数学公式严格推导出的结果
